package com.td.module.farmer.dal.mysql.plantinginformation;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.td.framework.common.pojo.PageResult;
import com.td.framework.mybatis.core.mapper.BaseMapperX;
import com.td.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.td.module.farmer.controller.admin.plantinginformation.vo.PlantingInformationExportReqVO;
import com.td.module.farmer.controller.admin.plantinginformation.vo.PlantingInformationPageReqVO;
import com.td.module.farmer.controller.admin.plantinginformation.vo.PlantingInformationSumVO;
import com.td.module.farmer.dal.dataobject.plantinginformation.PlantingInformationDO;
import org.apache.ibatis.annotations.Mapper;

import java.math.BigDecimal;
import java.util.List;

/**
 * 种植信息 Mapper
 *
 * @author 王翔翔
 */
@Mapper
public interface PlantingInformationMapper extends BaseMapperX<PlantingInformationDO> {

    default PageResult<PlantingInformationDO> selectPage(PlantingInformationPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<PlantingInformationDO>()
                .likeIfPresent(PlantingInformationDO::getPlantingName, reqVO.getPlantingName())
                .betweenIfPresent(PlantingInformationDO::getPlantingTime, reqVO.getPlantingTime())
                .eqIfPresent(PlantingInformationDO::getPlantingCycle, reqVO.getPlantingCycle())
                .eqIfPresent(PlantingInformationDO::getAgroReviewStorageMethod, reqVO.getAgroReviewStorageMethod())
                .betweenIfPresent(PlantingInformationDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(PlantingInformationDO::getId));
    }

    default List<PlantingInformationDO> selectList(PlantingInformationExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<PlantingInformationDO>()
                .likeIfPresent(PlantingInformationDO::getPlantingName, reqVO.getPlantingName())
                .betweenIfPresent(PlantingInformationDO::getPlantingTime, reqVO.getPlantingTime())
                .eqIfPresent(PlantingInformationDO::getPlantingCycle, reqVO.getPlantingCycle())
                .eqIfPresent(PlantingInformationDO::getAgroReviewStorageMethod, reqVO.getAgroReviewStorageMethod())
                .betweenIfPresent(PlantingInformationDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(PlantingInformationDO::getId));
    }

    default Long selectCount(Long id) {
        return selectCount(new LambdaQueryWrapper<PlantingInformationDO>().eq(PlantingInformationDO::getFarmerId, id));
    }

    default Integer delete(Long id) {
        return delete(new LambdaQueryWrapper<PlantingInformationDO>().eq(PlantingInformationDO::getFarmerId,id));
    }

    default List<PlantingInformationDO> selectListPlating(Long id) {
        return selectList(new LambdaQueryWrapper<PlantingInformationDO>().eq(PlantingInformationDO::getFarmerId,id));
    }

    PlantingInformationSumVO sumLandAndArea();

    BigDecimal calculateLandArea(Long id);
}
